Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
I'm fetching dynamic data from my nodejs to reactjs but I get an error saying "POST IS NOT DEFINED"

I have made entries in my mongodb database using node now I'm trying to fetch that data from backend to react front-end the 3rd party app used for cross-platform in node are cors and for react is axios(in script I have added "proxy":"http://localhost:5000"(5000 is my backend port)

Here is my code for NovelCard.js

import React, { Component } from 'react';
import { Container } from 'react-bootstrap';
import Card from 'react-bootstrap/Card';

import axios from 'axios';

const createSet = (post) => {
  <Card style={{ width: '18rem' }}>
    <Card.Img variant="top" src="holder.js/100px180" />
    <Card.Body>
      <Card.Title>{post.name}</Card.Title>
      <Card.Subtitle className="mb-2 text-muted">{post.author}</Card.Subtitle>
      <Card.Text>{post.synopsis}</Card.Text>
    </Card.Body>
  </Card>;
};

class Latest extends Component {
  state = {
    name: '',
    author: '',
    synopsis: '',
    post: [],
  };

  componentDidMount = () => {
    this.getData();
  };

  getData = () => {
    axios
      .get('http://localhost:5000/novels/')
      .then((res) => {
        const data = res.data;
        this.setState({ post: data });
        console.log('data recived');
      })
      .catch(() => {
        alert('error');
      });
  };


  render() {
    console.log('state', this.state);
    return <Container>{post.map(createSet)}</Container>;
  }
}
export default Latest;

I'm getting error saying ***

src\components\home\Latest\NovelCard.js Line 45:24: 'post' is not defined no-undef


over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your post variable is available within you state. You need to do something like this within your render function.

render() {
  console.log('state', this.state);
  return <Container>{this.state.post.map(createSet)}</Container>;
}

Or you can do like this as well.

render() {
  const { post } = this.state;
  console.log('state', this.state);
  return <Container>{post.map(createSet)}</Container>;
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda